001    /* $RCSfile: DESede2KeySecretKeyFactoryEngine.java,v $
002     * $Revision: 1.11 $
003     * $Date: 2003/10/04 19:18:38 $
004     * $Author: uwe_guenther $
005     * $State: Exp $
006     *
007     * Created on August 13, 2001 9:45 PM
008     *
009     * Copyright (C) 2001 Uwe Guenther <uwe@cscc.de>
010     *
011     * This file is part of the jhbci JCE-ServiceProvider. The jhbci JCE-
012     * ServiceProvider is a library, written in JavaTM, that should be 
013     * used in HBCI banking applications (clients and may be servers),
014     * to do cryptographic operations.
015     *
016     * The jhbci library is free software; you can redistribute it and/or
017     * modify it under the terms of the GNU Lesser General Public
018     * License as published by the Free Software Foundation; either
019     * version 2.1 of the License, or (at your option) any later version.
020     *
021     * The jhbci library is distributed in the hope that it will be useful,
022     * but WITHOUT ANY WARRANTY; without even the implied warranty of
023     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
024     * Lesser General Public License for more details.
025     *
026     * You should have received a copy of the GNU Lesser General Public
027     * License along with this library; if not, write to the Free Software
028     * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
029     *
030     */
031    
032    package de.cscc.crypto.provider;
033    
034    import java.security.InvalidKeyException;
035    import java.security.spec.InvalidKeySpecException;
036    import java.security.spec.KeySpec;
037    
038    import javax.crypto.SecretKey;
039    import javax.crypto.SecretKeyFactorySpi;
040    
041    /** 
042     * DESede2KeySecretKeyFactoryEngine Class.
043     *
044     * @author  <a href=mailto:uwe@cscc.de>Uwe Günther</a>
045     * @version $Revision: 1.11 $
046     */
047    public final class DESede2KeySecretKeyFactoryEngine extends SecretKeyFactorySpi {
048    
049        /** The delegate for this wrapper object */
050        private DESede2KeySecretKeyFactoryImpl factory = 
051        new DESede2KeySecretKeyFactoryImpl();
052        
053        /** 
054         * Creates a new DESede2KeySecretKeyFactoryEngine.
055         *
056         * @throws SecurityException if the provider self integrity check fails. 
057         */
058        public DESede2KeySecretKeyFactoryEngine() {
059            if (JHBCI.selfIntegrityChecking() == false) {
060                throw new SecurityException("JHBCI-Provider is tampered.");
061            }      
062        }
063        
064        /** 
065         * Returns a string representation of the object.
066         *
067         * @return a string representation of the object.
068         */
069        public String toString() {
070            return this.factory.toString();
071        }        
072    
073        /** 
074         * Generates a <code>SecretKey</code> object from the
075         * provided key specification (key material).
076         *
077         * @param keySpec the specification (key material) of the secret key.
078         * @return the secret key.
079         * @throws NullPointerException if keySpec is null.
080         * @throws InvalidKeySpecException if the given key specification
081         * is inappropriate for this secret-key factory to produce a secret key.
082         */
083        protected SecretKey engineGenerateSecret(KeySpec keySpec) 
084                throws InvalidKeySpecException {
085             return this.factory.generateSecret(keySpec);
086        }
087        
088        /** 
089         * Returns a specification (key material) of the given key object in the
090         * requested format.
091         *
092         * @param key the key.
093         * @param keySpec the requested format in which the key material shall be
094         * returned.
095         * @return the underlying key specification (key material) in the requested
096         * format.
097         * @throws NullPointerException if key or keySpec is null.
098         * @throws InvalidKeySpecException if the requested key specification is
099         * inappropriate for the given key (e.g., the algorithms associated with
100         * <code>key</code> and <code>keySpec</code> do not match, or
101         * <code>key</code> references a key on a cryptographic hardware device
102         * whereas <code>keySpec</code> is the specification of a software-based
103         * key), or the given key cannot be dealt with (e.g., the given key has
104         * an algorithm or format not supported by this secret-key factory).
105         */
106        protected KeySpec engineGetKeySpec(SecretKey key, Class keySpec) 
107                throws InvalidKeySpecException {
108            return this.factory.getKeySpec(key, keySpec);
109        }
110        
111        /** 
112         * Translates a key object, whose provider may be unknown or potentially
113         * untrusted, into a corresponding key object of this secret-key factory.
114         *
115         * @return they key whose provider is unknown or untrusted.
116         * @param key the key whose provider is unknown or untrusted.
117         * @throws NullPointerException if key is null.
118         * @throws InvalidKeyException if the given key cannot be processed by this
119         * secret-key factory.
120         */
121        protected SecretKey engineTranslateKey(SecretKey key) 
122                throws InvalidKeyException {
123            return this.factory.translateKey(key);
124        }
125    }